import cv2
from pathlib import Path
import time

index = 0

current_path = Path(__file__).resolve()
parent_path = current_path.parent.parent
import cv2
print(cv2.cuda.getCudaEnabledDeviceCount())
start_time = time.time()

while True:
    filename = str(index)
    folder = parent_path / "captureVideo" / "rgb" / filename
    # print(str(folder))
    img = "frame_" + str(index) + ".jpg"
    img_name = parent_path / "img" / "rgb" / img
    capture = cv2.VideoCapture(str(folder))
    # capture = cv2.VideoCapture(str(folder), cv2.CAP_FFMPEG, [cv2.CAP_PROP_HW_ACCELERATION, cv2.VIDEO_ACCELERATION_ANY])

    i = 0
    while True:
        img = "frame_" + str(index) + "_" + str(i) + ".jpg"
        img_name = parent_path / "img" / "rgb" / img
        ret, frame = capture.read()
        if frame is None:
            break
        i = i + 1
        cv2.imwrite(str(img_name), frame)
        print(f"pic_{index} saved")

    index = index + 1
    if index > 10:
        break

end_time = time.time()
print(f"time: {end_time - start_time}")